package com.up.vms.domain.vm.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import com.up.vms.domain.vm.entity.Video;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;

public interface VideoRepository extends JpaRepository<Video, Long>, JpaSpecificationExecutor<Video> {
    long countByCategoryId(Long categoryId);

    Page<Video> findAllByVideoNameLikeAndStatus(String videoName, Integer status, Pageable pageable);

    Page<Video> findAllByRecommendFlagAndShowVideoModeAndStatus(Integer recommendFlag, Integer showVideoMode,Integer status, Pageable pageable);

    @Modifying
    @Query(value = "update T_VMS_Video v set v.play_times = v.play_times + 1 where v.id = ?1", nativeQuery = true)
    void updatePlayTimes(Long id);
}
